package com.yunhe.authority.controller.base;

import com.yunhe.authority.domain.base.MessageCenter;
import com.yunhe.authority.model.base.*;
import com.yunhe.authority.service.base.MessageCenterService;
import com.yunhe.common.model.PageParam;
import com.yunhe.common.model.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MessageCenterController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/10/18 17:13
 * @Version 1.0
 **/
@Api(value = "messageCenter",description = "Authority_MessageCenter", tags = {"消息中心"})
@RestController
@RequestMapping("/messageCenter")
public class MessageCenterController {


    @Autowired
    private MessageCenterService messageCenterService;

    /**
     * 新增
     * @author misty
     * @date 2021/10/18
     **/
    @ApiOperation("新增消息中心")
    @PostMapping("/createMessageCenter")
    public ResponseEntity<ResultObject<MessageCenter>> createMessageCenter(@RequestBody MessageCenter messageCenter){
        MessageCenter newMessageCenter = messageCenterService.createMessageCenter(messageCenter);
        return new ResponseEntity<>(new ResultObject<>(newMessageCenter), HttpStatus.OK);
    }

    @ApiOperation("批量新增消息中心数据")
    @PostMapping("/batchCreateMessageCenter")
    public ResponseEntity<ResultObject> batchCreateMessageCenter(@RequestBody List<MessageCenter> messageCenters){
        messageCenterService.batchCreateMessageCenter(messageCenters);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author misty
     * @date 2021/10/18
     **/
    @ApiOperation("根据id删除消息中心")
    @DeleteMapping("/deleteMessageCenter")
    public ResponseEntity<ResultObject> deleteMessageCenter(@RequestParam(value = "id",required = true) Long id){
        messageCenterService.deleteMessageCenter(id);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 更新
     * @author misty
     * @date 2021/10/18
     **/
    @ApiOperation("更新消息中心")
    @PostMapping("/updateMessageCenter")
    public ResponseEntity<ResultObject<MessageCenter>> updateMessageCenter(@RequestBody MessageCenter messageCenter){
        MessageCenter newMessageCenter = messageCenterService.updateMessageCenter(messageCenter);
        return new ResponseEntity<>(new ResultObject<>(newMessageCenter), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/10/18
     **/
    @ApiOperation("根据id查询消息中心")
    @GetMapping("/findMessageCenterById")
    public ResponseEntity<ResultObject<MessageCenter>> findMessageCenterById(@RequestParam(value = "id",required = true) Long id){
        return new ResponseEntity<>(new ResultObject(messageCenterService.findMessageCenterById(id)),HttpStatus.OK);
    }

    @ApiOperation("查询app个人消息")
    @PostMapping("/findAppMessage")
    public ResponseEntity<ResultObject<List<MessageCenterVo>>> findAppMessage(@RequestBody  PageParam pageParam){
        Iterable<MessageCenterVo> messageCenters = messageCenterService.findAppMessage(pageParam);
        return new ResponseEntity<>(new ResultObject(messageCenters),HttpStatus.OK);
    }

    @ApiOperation("查询小程序个人消息")
    @PostMapping("/findWeChatMessage")
    public ResponseEntity<ResultObject<List<MessageCenterVo>>> findWeChatMessage(@RequestBody MessageQueryCondition messageQueryCondition){
        Iterable<MessageCenterVo> messageCenters = messageCenterService.findWeChatMessage(messageQueryCondition);
        return new ResponseEntity<>(new ResultObject(messageCenters),HttpStatus.OK);
    }

    @ApiOperation("根据条件查询消息已读未读条数")
    @GetMapping("/getMessageCountByCondition")
    public ResponseEntity<ResultObject<MessageReadCount>> getMessageCountByCondition(@RequestParam(value = "businessId",required = true) Long businessId,
                                                                                     @RequestParam(value = "messageType",required = true) String messageType){
        return new ResponseEntity<>(new ResultObject(messageCenterService.getMessageCountByCondition(businessId,messageType)),HttpStatus.OK);
    }


    @ApiOperation("根据条件查询消息已读未读信息")
    @PostMapping("/findMessageByCondition")
    public ResponseEntity<ResultObject<Iterable<MessageReadVo>>> findMessageByCondition(@RequestBody WhetherReadQueryCondition whetherReadQueryCondition){
        return new ResponseEntity<>(new ResultObject(messageCenterService.findMessageByCondition(whetherReadQueryCondition)),HttpStatus.OK);
    }

}
